home *** CD-ROM | disk | FTP | other *** search
- From: bglenden@colobus.aoc.nrao.edu (Brian Glendenning)
- Message-ID: <BGLENDEN.96Apr12135956@colobus.aoc.nrao.edu>
- X-Original-Date: 12 Apr 1996 19:59:56 GMT
- Path: in1.uu.net!bounce-back
- Date: 14 Apr 96 11:52:54 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: Use of standard exception classes
- Organization: National Radio Astronomy Observatory, Socorro NM
- References: <9604121530.AA08606@sun132.spd.dsccc.com>
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMXDnJOEDnX0m9pzZAQE5jwF8C3VygF8w9WaTVRaMancWgK+OHUHZOWud
- OaJ/yRrSN+n1ShmDt2GGwoRD5n+vSeTq
- =G9Zo
-
- In a different topic, I'm confused about the different purpose ascribed to
- exceptions derived from logic_error:
-
- "The class logic_error defines the type of objects thrown as exceptions
- to report errors presumably *detectable before the program executes*,
- such as violations of logical preconditions or invariants."
-
- and runtime_error:
-
- "The class runtime_error defines the type of objects thrown as
- exceptions to report errors presumably only detectable when the program
- executes."
-
- It seems to me that with this wording most exceptions should be derived from
- runtime_error.
- However, basic_string<...>::remove(size_type pos = 0, size_type n = npos),
- for example, throws out_of_range (derived from logic error).
-
- Unless the program only runs with manifest constants, it can't detect this
- problem before the program executs:
- cin >> pos; mystring.remove(pos);
-
- So why does it throw a logic_error rather than a runtime_error? Thanks!
-
- (I'm also interested in learning whether it's a good idea to derive our
- exceptions from standard exceptions).
-
- Brian
- --
- Brian Glendenning - National Radio Astronomy Observatory
- bglenden@nrao.edu Socorro NM (505) 835-7347
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-